$(function(){

	/*页面载入的时候全部显示灰色*/
	$('.newPrize-now p').html('?');
	$('.getPrize-circular1 p').html('?');
	$('.getPrize-circular2 p').html('?');
	$('.getPrize-circular3 p').html('?');
	$('.newPrize-now').css({'background':'#d0d0d0','border':'8px solid #BEBEBE'});
	$('.getPrize-circular1').css({'background':'#d0d0d0','border':'8px solid #BEBEBE'});
	$('.getPrize-circular2').css({'background':'#d0d0d0','border':'8px solid #BEBEBE'});
	$('.getPrize-circular3').css({'background':'#d0d0d0','border':'8px solid #BEBEBE'});

	/*伪造数据*/

	// var data = {
	// 	status : 1,
	// 	msg: {
	// 		jing: 1,
	// 		ke: 1,
	// 		long: 1
	// 	}
	// }

	// var data = {
	// 	status: 0,
	// 	msg: {
	// 		jing:'',
	// 		ke: 1,
	// 		long: 1,
	// 	},
	// 	newPrize: 'jing'
	// }

	var getUrlParam = function(name){
        var reg     = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
        var result  = window.location.search.substr(1).match(reg);
        return result ? decodeURIComponent(result[2]) : '';
    };
    // 新获取的奖品
    var newPrize = getUrlParam('name');
    var userid = getUrlParam('userid');

    // console.log(newPrize);

    var txtAndcolor = {
			jing: ["京","#a4cf27","8px solid #7ea936"],
			ke  : ["客","#4fc5cf","8px solid #2ba7b3"],
			long: ["隆","#fec22e","8px solid #f7a100"],
			noget:["无","#fec22e","8px solid #f7a100"]
		}

		var getprizebg     = txtAndcolor[newPrize][1];	
		var getprizeborder = txtAndcolor[newPrize][2];	

		if(newPrize == 'jing'){
			 $('.newPrize-now p').html('京');
			 $('.newPrize-now').css({"background": getprizebg,
			  						  "border"    : getprizeborder
										})
		}
		else if(newPrize == 'ke'){
			 $('.newPrize-now p').html('客');
			 $('.newPrize-now').css({"background": getprizebg,
			  						  "border"   : getprizeborder
										})
		}
		else if(newPrize == 'long'){
			 $('.newPrize-now p').html('隆');
			 $('.newPrize-now').css({"background": getprizebg,
			  						  "border"   : getprizeborder
										})
		}
		else if(newPrize == 'noget'){
			 $('.newPrize-now p').html('');
			 $('.newPrize-now').css({"background": getprizebg,
			  						  "border"   : getprizeborder
										})
		}

function myrender(data){	

	
	var txtAndcolorget = {
			first   : ["京","#a4cf27","8px solid #7ea936"],
			second  : ["客","#4fc5cf","8px solid #2ba7b3"],
			third   : ["隆","#fec22e","8px solid #f7a100"]
		}	

	if(data.data.status==0){

		var msgArr = Object.keys(data.data);

		for(var i=0;i<5;i++){

			if(msgArr[i]=='status'||msgArr[i]=='activity_id'){

				msgArr.splice(i);
			}
		}
		// console.log(msgArr);

		msgArr.forEach(function(item,index){
			if(data.data[item] == 1){
				// console.log(item);
				var newitem 	= '#' + item + ' p';
				var newitemCss  = '#' + item;	
				var newtxt 		= txtAndcolorget[item][0];
				var newbg       = txtAndcolorget[item][1];
				var newborder   = txtAndcolorget[item][2];
				$(newitem).html(newtxt);
				$(newitemCss).css('background',newbg);
				$(newitemCss).css('border',newborder);
			}
		});
	}


// 第三次抽奖发券的情况
	 else if(data.data.status==1){
	 		setTimeout(function(){
	 			$('.newPrize').css('display','none');
				$('.card').css('display','block');
				$('.getPrize-circular1 p').html('京');
				$('.getPrize-circular2 p').html('客');
				$('.getPrize-circular3 p').html('隆');
				$('.getPrize-circular1').css({'background':'#a4cf27','border':'8px solid #7ea936'});
				$('.getPrize-circular2').css({'background':'#4fc5cf','border':'8px solid #2ba7b3'});
				$('.getPrize-circular3').css({'background':'#fec22e','border':'8px solid #f7a100'});
	 		},500)
		}
		// $('.leftline').css('display','none');
		// $('.middleline').css('display','none');
		// $('.rightline').css('display','none');
// 抽过三次而且已经获取过优惠券的情况
	 else if(data.data.status==2){
		$('.newPrize-now p').html('京');
		$('.getPrize-circular1 p').html('京');
		$('.getPrize-circular2 p').html('客');
		$('.getPrize-circular3 p').html('隆');
		$('.newPrize-now').css({'background':'#4fc3d0','border':'8px solid #2ca8b2'});
		$('.getPrize-circular1').css({'background':'#a4cf27','border':'8px solid #7ea936'});
		$('.getPrize-circular2').css({'background':'#4fc5cf','border':'8px solid #2ba7b3'});
		$('.getPrize-circular3').css({'background':'#fec22e','border':'8px solid #f7a100'});
		$('.newPrize').css('display','none');
		$('.card').css('display','block');
		$('.card-bottom p').html('您已获取过')
		$('.leftline').css('display','none');
		$('.middleline').css('display','none');
		$('.rightline').css('display','none');
	}


}	

	 $.ajax({
        type: "get",
        url: 'http://mobinterface.jkl.com.cn/api?app=Bts&class=CouponActivitySet&userid=' + userid,

        success: function (data) {
        	console.log(data);
            myrender(data);

        }
    });

	 $('.bb p').bind("click",function(){
	 	$('.rules').css("display","block");
	 })
	  $('#myrule').bind("click",function(){
	 	$('.rules').css("display","none");
	 })

})